#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
配置文件
包含所有应用配置项
"""

import os
from typing import Dict, Any

class Settings:
    """应用配置类"""
    
    # 企业微信群机器人配置
    WEBHOOK_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=eb313ad3-b491-4d21-ae60-d1c93b9beef0'
    SECRET = 'eb313ad3-b491-4d21-ae60-d1c93b9beef0'
    
    # 企业微信应用配置
    WX_TOKEN = 'Sv3mVW1LOIU'
    WX_AES_KEY = 'NgHrjQdRw46FQIyTedXxJu6GrjqcoewHWlCQVLA76Ai'
    WX_CORPID = 'wxc4c1ad1d26dc0daf'
    WX_RECEIVE_ID = 'wxc4c1ad1d26dc0daf'  # 企业微信客服OpenKfId
    KF_ID = 'kfc8a7f94bc2a780bab'
    WX_CORPSECRET = 'dMblb8p05YDN_uxiO8-DgRlPhXqHKc7aofUNC1Xlk6s'
    OPEN_KF_ID = 'wktI2SEAAABFbkw58saEfQgexjHIj5sQ' # 客服接待的open_kfid
    WX_AGENT_ID = '1000004'  # 企业微信应用ID，用于发送内部消息（根据测试结果更新）
    WX_AGENT_SECRET = 'dMblb8p05YDN_uxiO8-DgRlPhXqHKc7aofUNC1Xlk6s'  # 企业微信应用Secret
    
    # 服务器配置
    HOST = '0.0.0.0'
    PORT = 5005
    
    # 日志配置
    LOG_LEVEL = 'INFO'
    LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    LOG_FILE = 'logs/bot.log'
    
    # 消息处理配置
    MAX_MESSAGE_LENGTH = 2000
    RESPONSE_TIMEOUT = 30
    
    # AI配置
    AI_MODEL = 'gpt-3.5-turbo'
    AI_MAX_TOKENS = 1000
    AI_TEMPERATURE = 0.7
    
    @classmethod
    def get_env_vars(cls) -> Dict[str, str]:
        """获取环境变量配置"""
        return {
            'WEBHOOK_URL': cls.WEBHOOK_URL,
            'SECRET': cls.SECRET,
            'WX_TOKEN': cls.WX_TOKEN,
            'WX_AES_KEY': cls.WX_AES_KEY,
            'WX_CORPID': cls.WX_CORPID,
            'WX_RECEIVE_ID': cls.WX_RECEIVE_ID,
            'KF_ID': cls.KF_ID,
            'WX_CORPSECRET': cls.WX_CORPSECRET,
            'WX_AGENT_ID': cls.WX_AGENT_ID,
            'WX_AGENT_SECRET': cls.WX_AGENT_SECRET,
            'HOST': cls.HOST,
            'PORT': str(cls.PORT),
            'LOG_LEVEL': cls.LOG_LEVEL,
            'MAX_MESSAGE_LENGTH': str(cls.MAX_MESSAGE_LENGTH),
            'RESPONSE_TIMEOUT': str(cls.RESPONSE_TIMEOUT),
            'OPEN_KF_ID': cls.OPEN_KF_ID
        }
    
    @classmethod
    def load_from_env(cls):
        """从环境变量加载配置"""
        cls.WEBHOOK_URL = os.getenv('WEBHOOK_URL', cls.WEBHOOK_URL)
        cls.SECRET = os.getenv('SECRET', cls.SECRET)
        cls.WX_TOKEN = os.getenv('WX_TOKEN', cls.WX_TOKEN)
        cls.WX_AES_KEY = os.getenv('WX_AES_KEY', cls.WX_AES_KEY)
        cls.WX_CORPID = os.getenv('WX_CORPID', cls.WX_CORPID)
        cls.WX_RECEIVE_ID = os.getenv('WX_RECEIVE_ID', cls.WX_RECEIVE_ID)
        cls.KF_ID = os.getenv('KF_ID', cls.KF_ID)
        cls.WX_CORPSECRET = os.getenv('WX_CORPSECRET', cls.WX_CORPSECRET)
        cls.WX_AGENT_ID = os.getenv('WX_AGENT_ID', cls.WX_AGENT_ID)
        cls.WX_AGENT_SECRET = os.getenv('WX_AGENT_SECRET', cls.WX_AGENT_SECRET)
        cls.OPEN_KF_ID = os.getenv('OPEN_KF_ID', cls.OPEN_KF_ID)
        cls.HOST = os.getenv('HOST', cls.HOST)
        cls.PORT = int(os.getenv('PORT', cls.PORT))
        cls.LOG_LEVEL = os.getenv('LOG_LEVEL', cls.LOG_LEVEL)
        cls.MAX_MESSAGE_LENGTH = int(os.getenv('MAX_MESSAGE_LENGTH', cls.MAX_MESSAGE_LENGTH))
        cls.RESPONSE_TIMEOUT = int(os.getenv('RESPONSE_TIMEOUT', cls.RESPONSE_TIMEOUT))

# 创建配置实例
settings = Settings() 